package com.stylefeng.guns.rest.modular.wz.api.v3;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.rest.common.base.controller.ApiBaseController;
import com.stylefeng.guns.rest.common.constant.Consts;
import com.stylefeng.guns.rest.common.persistence.dao.*;
import com.stylefeng.guns.rest.common.persistence.model.*;
import com.stylefeng.guns.rest.domain.ParamMap;
import com.stylefeng.guns.rest.domain.Res;
import com.stylefeng.guns.rest.enums.EnWzAdvMap;
import com.stylefeng.guns.rest.enums.EnWzMapActivity;
import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil;
import com.stylefeng.guns.rest.modular.wz.api.v3.dao.WzAdvMapDao;
import com.stylefeng.guns.rest.modular.wz.api.v3.service.IWzAdvMapService;
import com.stylefeng.guns.rest.modular.wz.api.v3.service.impl.WzAdvMapServiceImpl;
import com.stylefeng.guns.rest.modular.wz.api.v3.service.impl.WzUserActivityServiceImpl;
import com.stylefeng.guns.rest.modular.wz.cache.CacheService;
import com.stylefeng.guns.rest.modular.wz.service.IPfFileService;
import com.stylefeng.guns.rest.modular.wz.service.IWzUserInfoService;
import com.stylefeng.guns.rest.modular.wz.service.IWzUserService;
import com.stylefeng.guns.rest.modular.wz.service.impl.WzAdvServiceImpl;
import com.stylefeng.guns.rest.modular.wz.util.AliOssUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 提现页面
 */
@RestController
@RequestMapping("/wz/api/v3/cash/")
public class WzCashApi extends ApiBaseController {

    @Autowired
    private WzUserActivityServiceImpl userActivityService;

    /**
     * 我的店铺
     */
    @PostMapping("myAdvMapList")
    public Res myAdvMapList(@RequestBody ParamMap paramMap) {
        //业务处理
        Res res = userActivityService.myAdvMapList(paramMap);
        return res;
    }

    /**
     * 店铺活动
     */
    @PostMapping("myAdvMapActivityList")
    public Res myAdvMapActivityList(@RequestBody ParamMap paramMap) {
        //业务处理
        Res res = userActivityService.myAdvMapActivityList(paramMap);
        return res;
    }

    /**
     * 店铺广告红包
     */
    @PostMapping("myAdvMapAdvList")
    public Res myAdvMapAdvList(@RequestBody ParamMap paramMap) {
            //业务处理
            Res res = userActivityService.myAdvMapAdvList(paramMap);
            return res;
    }

    /**
     * 发布的券
     */
    @PostMapping("myAdvMapCouponList")
    public Res myAdvMapCouponList(@RequestBody ParamMap paramMap) {
        //版本判断
        String androidVersion = paramMap.getStrValid("androidVersion");
        String iosVersion = paramMap.getStrValid("iosVersion");
        int ios = 0;
        int android = 0;
        if(StringUtils.isNotBlank(iosVersion)){
            ios = Integer.parseInt(iosVersion.substring(0,1))*100 + Integer.parseInt(iosVersion.substring(2,3))*10 + Integer.parseInt(iosVersion.substring(4,5));
        }
        if(StringUtils.isNotBlank(androidVersion)){
            android = Integer.parseInt(androidVersion);
        }
        if(android > 30 || ios > 150){//新务处理
            Res res = userActivityService.newMyAdvMapCouponList(paramMap);
            return res;
        }else{//旧业务处理
            Res res = userActivityService.myAdvMapCouponList(paramMap);
            return res;
        }
    }

    /**
     * 返利活动列表
     */
    @PostMapping("mapRebateList")
    public Res mapRebateList(@RequestBody ParamMap paramMap) {
        Res res=userActivityService.mapRebateList(paramMap);
        return Res.success();
    }

    /**
     * 新增活动
     */
    @PostMapping("addMapActivity")
    public Res addActivity(@RequestBody ParamMap paramMap) throws Exception{
        Res res=userActivityService.addMapActivity(paramMap);
        return res;
    }

    /**
     * 新增商城礼券
     */
    @PostMapping("addWzCoupon")
    public Res addWzCoupon(@RequestBody ParamMap paramMap) throws Exception{
        Res res=userActivityService.addWzCoupon(paramMap);
        return res;
    }

    /**
     * 券库商城列表
     */
    @PostMapping("couponList")
    public Res couponList(@RequestBody ParamMap paramMap){
        Res res=userActivityService.couponList(paramMap);
        return res;
    }
    /**
     *  购买礼券
     */
    @PostMapping("buyCoupon")
    public Res buyCoupon(@RequestBody ParamMap paramMap){
        Res res=userActivityService.buyCoupon(paramMap);
        return res;
    }


    /**
     *  购买的礼券列表
     */
    @PostMapping("myCouponList")
    public Res myCouponList(@RequestBody ParamMap paramMap){
        Res res=userActivityService.myCouponList(paramMap);
        return res;
    }

    /**
     * 店铺活动参与列表
     */
    @PostMapping("mapActivityJoinList")
    public Res mapActivityJoinList(@RequestBody ParamMap paramMap) {
        //业务处理
        Res res = userActivityService.mapActivityJoinList(paramMap);
        return res;
    }

    /**
     * 修改驳回礼券
     */
    @PostMapping("editWzCoupon")
    public Res editWzCoupon(@RequestBody ParamMap paramMap) throws Exception {
        //业务处理
        Res res = userActivityService.editWzCoupon(paramMap);
        return res;
    }
    /**
     * 删除驳回礼券
     */
    @PostMapping("deleteWzCoupon")
    public Res deleteWzCoupon(@RequestBody ParamMap paramMap) throws Exception {
        //业务处理
        Res res = userActivityService.deleteWzCoupon(paramMap);
        return res;
    }
    /**
     * 礼券使用列表
     */
    @PostMapping("couponUsedList")
    public Res couponUsedList(@RequestBody ParamMap paramMap){
        //业务处理
        Res res = userActivityService.couponUsedList(paramMap);
        return res;
    }

    /**
     * 礼券卖出列表
     */
    @PostMapping("couponSoldList")
    public Res couponSoldList(@RequestBody ParamMap paramMap){
        //业务处理
        Res res = userActivityService.couponSoldList(paramMap);
        return res;
    }

}
